import { Controller, Get, Param, Inject, Optional } from '@nestjs/common';
import { UserService } from './user.service';
import { ConfigService } from './config.service';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { ApiResponse } from '@nestjs/swagger';

@Controller('optional-providers')
@ApiTags('可选提供者')
export class OptionalProvidersController {
  constructor(
    private readonly userService: UserService,
    private readonly configService: ConfigService,
    @Optional() @Inject('CONFIG_OPTIONS') private readonly configOptions: any,
  ) { }

  @Get('config')
  @ApiOperation({ summary: '获取配置信息', description: '返回应用配置信息' })
  @ApiResponse({ status: 200, description: '成功获取配置信息' })
  getConfig(): ReturnType<typeof this.configService.getConfig> {
    return {
      ...this.configService.getConfig(),
      // 展示原始注入的配置（如果有）
      ...(this.configOptions ? { injectedConfig: this.configOptions } : { injectedConfig: 'No custom config provided' }),
    };
  }

  @Get('user-config-info')
  @ApiOperation({ summary: '获取用户配置信息', description: '返回用户配置信息' })
  @ApiResponse({ status: 200, description: '成功获取用户配置信息' })
  getUserConfigInfo() {
    return this.userService.getUserConfigInfo();
  }

  @Get('user/:id')
  @ApiOperation({ summary: '获取用户信息', description: '根据用户ID获取用户信息' })
  @ApiResponse({ status: 200, description: '成功获取用户信息' })
  async getUser(@Param('id') id: string) {
    return this.userService.fetchUserData(id);
  }
}